
/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-07 14:47:03
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-01-07 15:48:05
 */
import netCtr from "../ctrs/netCtr";
import victoryEntity from "../ctrs/victory/victoryEntity";
import BaseGameComponent from "../libs/core/BaseGameComponent";
import { PureMVCEvents } from "../libs/core/PureMVCEvents";
import { INotification } from "../libs/pureMvc/Interfaces";

const { ccclass, property } = cc._decorator;
@ccclass
export default class victoryCom extends BaseGameComponent {

  @property({ type: cc.Label, tooltip: "描述" })
  txt: cc.Label = null;

  private _victoryEntity: victoryEntity;

  drawUi(data = null) {
    if (data)
      this._victoryEntity = data;

    // console.log(this._victoryEntity)
    this.txt.string = (this._victoryEntity.btnStr as any).str;
  }

  public listNotificationInterests(): string[] {
    return [PureMVCEvents.ON_VICTORY_UPDATE];
  }

  public handleNotification(notification: INotification): void {
    let evtName = notification.getName();
    switch (evtName) {
      case PureMVCEvents.ON_VICTORY_UPDATE:
        this.drawUi();
        break;
    }
  }

  onClick() {
    if ((this._victoryEntity.btnStr as any).isCan) {
      netCtr.ins.getVictoryReward(this._victoryEntity.id);
    }
  }
}